<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index() {
        $actors = new \App\Models\Actors();
        $records = $actors->findAll();
        $table = new \CodeIgniter\View\Table();
        $headings = $actors->fields;
        $displayHeadings = array_slice($headings, 1, 3);
        $table->setHeading(array_map('ucfirst', $displayHeadings));
        foreach ($records as $record) {
            $DLink = anchor("Movie/showme/$record->id", 'Detail');
            $table->addRow( $record->name,'<img src="/image/'.$record->image.'">',$DLink);
        }
        $template = [
            'table_open' => '<table cellpadding="10px">',
            'cell_start' => '<td style="border: 1px solid #dddddd;">',
            'row_alt_start' => '<tr style="background-color:#dddddd">',
        ];
        $table->setTemplate($template);
         $fields = [
            'title' => 'Actor Introduced ',
            'heading' => 'Hong Kong Action Actor ',
            'footer' => 'Copyright ZhongJingChong'
        ];
        // get a template parser
        $parser = \Config\Services::parser();
         return $parser->setData($fields)
                        ->render('templates\top') .
                $table->generate() .
                        $parser->setData($fields)
                        ->render('templates\bottom');
    }
    
}